package shiyl.use.springboot.config;

import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import shiyl.use.springboot.config.fabric.FabricDefinitionMng;
import shiyl.use.springboot.utils.JsonUtils;

/**
 * 自定义配置信息管理器
 * @author  shiyl
 */
@Data
@ToString
@Slf4j
@ConfigurationProperties(prefix = "customer")
public class CustomerDefinition {

    @Autowired
    Environment environment ;
    private final static String ACTIVE = "spring.profiles.active" ;

    @Autowired
    FabricDefinitionMng fabricDefinitionMng ;

    // 加载 resource/application.yml
    private String key1 ;

    // 加载 config/application.yml
    private String key2 ;

    // 加载 config/application-syl-dev.yml
    private String key3 ;

    // 加载 config/application-syl-test.yml
    private String key4 ;

    public String getProfileActive(){
       return "从CustomerDefinition中获取spring.profiles.active = " + environment .getProperty(ACTIVE,"找不到!") ;
    }

    /**
     * 获取整个fabric配置对象
     * @return
     */
    public String getFabric(){
        return JsonUtils.jsonStrPattern(fabricDefinitionMng.toString()) ;
    }
}
